# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/10 21:50
# @Author   : Robot-Zsj
"""
description:

input
4
1 2 3 4
output
4
"""

n = int(input())
levels = list(map(int, input().split()))


def getResult():
    ans = 0

    for i in range(1, n - 1):
        mid = levels[i]

        leftSmallerCount = 0
        leftBiggerCount = 0

        for j in range(i):
            if levels[j] > mid:
                leftBiggerCount += 1
            else:
                leftSmallerCount += 1

        rightSmallerCount = 0
        rightBiggerCount = 0

        for k in range(i + 1, n):
            if levels[k] > mid:
                rightBiggerCount += 1
            else:
                rightSmallerCount += 1

        ans += leftSmallerCount * rightBiggerCount + leftBiggerCount * rightSmallerCount
    return ans


print(getResult())
